package com.huike.web.controller.report;
import java.text.SimpleDateFormat;
import com.huike.business.service.ITbBusinessService;
import com.huike.clues.domain.Index;
import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.clues.service.ITbAssignRecordService;
import com.huike.clues.service.ITbClueService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.report.domain.vo.Report;
import com.huike.report.service.IReportService;
import com.huike.report.service.impl.ReportServiceImpl;
import org.apache.logging.log4j.util.IndexedStringMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private ITbClueService tbClueService;

    @Autowired
    private ITbBusinessService tbBusinessService;
    @Autowired
    private IReportService reportService;


    /**
     * 线索转换龙虎榜
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic( String beginCreateTime,  String endCreateTime) {


        IndexStatisticsVo request = new IndexStatisticsVo();
        request.setBeginCreateTime(beginCreateTime);
        request.setEndCreateTime(endCreateTime);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        List<Map<String,Object>> list= tbClueService.clueChangeStatisticsForIndex(request);
        return AjaxResult.success(list);

    }

    /**
     * 商机转换龙虎榜
     * @param request
     * @return
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(IndexStatisticsVo request){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        List<Map<String,Object>> list= tbBusinessService.businessChangeStatisticsForIndex(request);
        return AjaxResult.success(list);
    }

    @GetMapping
    public AjaxResult contractStatistics(IndexStatisticsVo request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        Map<String,Object> result = reportService.getcontractsBasicInfo(request,sdf.format(new Date()));
        return AjaxResult.success(result);
    }
}
